﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using BLL;
using MOD;

namespace MapServer.Adhs
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class GetDevoted : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            String sReturnValue = String.Empty;
            if (context.Request["userId"] != null)
            {
                sReturnValue = GetDevotedCount(Convert.ToInt32(context.Request["userId"]) );
            }
            context.Response.Write(sReturnValue);
        }
        public String GetDevotedCount(Int32 iUserId)
        {
            B_AdInfo bAo = new B_AdInfo();
            B_AdRepost bAt = new B_AdRepost();
            int iOriginality = 0;   //创意
            int iCharm = 0;         //魅力
            int iContributions = 0; //贡献
            int iChildShoes = 0;    //童鞋
            String sValue = "998";
            try
            {
                DataTable dOriginality = new DataTable();
                DataTable dContributions = new DataTable();
                DataTable dCharm = new DataTable();
                
                dOriginality = bAo.SelectUserIdCount(iUserId);
                dContributions = bAo.SelectOtherUserId(iUserId);
                dCharm = bAt.SelectRepost(iUserId);

                if (dOriginality.Rows.Count != 0)
                {
                    iOriginality = Convert.ToInt32( dOriginality.Rows[0]["count"].ToString().Trim());
                }
                if(dContributions.Rows.Count != 0)
                {
                    iCharm = Convert.ToInt32(dContributions.Rows[0]["count"].ToString().Trim());
                }
                if(dCharm.Rows.Count != 0)
                {
                    iContributions = Convert.ToInt32(dCharm.Rows[0]["count"].ToString().Trim());
                }
                String[] sArrayList = new String[1];
                sArrayList[0] =   iUserId.ToString() + "," + iOriginality.ToString()+ "," + iCharm + "," +iContributions.ToString()+","+iChildShoes.ToString();
                sValue = JsonParameters.CreateJsonParameters(String.Empty, sValue,sArrayList);
               
            }
            catch
            {
                sValue = JsonParameters.CreateJsonParameters(String.Empty, sValue);            
            }
           
            return sValue; 
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
